import random
import uuid


class StorageOperations:
    def __init__(self):
        self._operationsList = [
            self._enumerateStorages,
            self._enumerateStorageStatistics
        ]
        self._baseStorage = {
            'name': 'Storage',
            'partnerId': 1,
            'locationId': 1
        }
        self._storagesCount = 5

    def _getRandomOperation(self):
        return random.choice(self._operationsList)

    def _createStorage(self, manserv, storageNumber):
        self._baseStorage['name'] = 'Storage_' + str(storageNumber)
        manserv.AddStorage(**self._baseStorage)

    def _createRandomStorage(self, manserv, partnerId):
        partnerId = manserv.GetPartnerInfoById(id = partnerId).id
        locationResult = manserv.EnumerateLocations()
        if len(locationResult.locationInfo) > 1:
            resultLenth = random.randint(1, len(locationResult.locationInfo)-1)
            locationId = locationResult.locationInfo[resultLenth].id
            self._baseStorage['name'] = uuid.uuid4()
            self._baseStorage['partnerId'] = partnerId
            self._baseStorage['locationId'] = locationId
            manserv.AddStorage(**self._baseStorage)

    def _enumerateStorages(self, manserv, partnerId):
         manserv.EnumerateStorages(parentId = partnerId)

    def _enumerateStorageStatistics(self, manserv, partnerId):
         manserv.EnumerateStorageStatistics(partnerId = partnerId)
